import request from '@/router/axios'
import {getStore, setStore} from "@/util/store.js";
import website from "@/const/website.js";


export const loginByUsername = (login) => {

  let basicAuth = 'Basic ' + window.btoa(website.formLoginClient)
  // 保存当前选中的 basic 认证信息
  setStore({
    name: 'basicAuth',
    content: basicAuth
  })
  return request({
    url: '/admin/auth/login',
    headers: {
      Authorization: basicAuth
    },
    method: 'post',
    data: login
  })
}

export const loginByMobile = (phone, code) => {
  let basicAuth = 'Basic ' + window.btoa(website.formLoginClient)
  // 保存当前选中的 basic 认证信息
  setStore({
    name: 'basicAuth',
    content: basicAuth
  })
  return request({
    url: '/admin/auth/smsLogin',
    headers: {
      Authorization: basicAuth
    },
    method: 'post',
    data: {phone: phone, code: code}
  })
}


export const getUserInfo = () => {
  return request({
    url: '/admin/auth/info',
    method: 'get'
  })
}

export const logout = (data) => {
  return request({
    url: '/open/oauth2/logout',
    method: 'delete',
    data: data
  })
}

/**
 * 注册用户
 */
export const registerUser = (userInfo) => {
  return request({
    url: '/admin/register/user',
    method: 'post',
    data: userInfo
  })
}
